package com.pagepub.expo.action.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.opensymphony.xwork2.ActionSupport;
import com.pagepub.expo.entity.AppDict;
import com.pagepub.expo.entity.CorpPublication;
import com.pagepub.expo.manager.AppSeqMng;
import com.pagepub.expo.manager.CorpPublicationMng;

public class CorpPublicationAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Autowired
	@Qualifier("corpPublicationMng")
	private CorpPublicationMng corpPublicationMng;
	
	@Autowired
	@Qualifier("appSeqMng")
	private AppSeqMng appSeqMng;

	
	public List<CorpPublication> rows = new ArrayList<CorpPublication>();

	public int start = 0;

	public int limit = 0;
	
	public int total;	
	

	private boolean success;

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}
	
	
	private CorpPublication corpPublication;

	public CorpPublicationAction() {
		System.out.println("this is AppDictAction");
	}

	public String execute() throws Exception {
		System.out.println("this is execute");
		return null;
	}

	public String all() {
		HttpServletRequest request = ServletActionContext.getRequest();
		int start = Integer.valueOf(request.getParameter("start"));
		int limit = Integer.valueOf(request.getParameter("limit"));
		String sortname = request.getParameter("sortname");
		String sortorder = request.getParameter("sortorder");
		HashMap<String, String> param = new HashMap<String, String>();
		if (sortname != null && sortname.length() > 0) {
			param.put("sortname", sortname);
		}
		if (sortorder != null && sortorder.length() > 0) {
			param.put("sortorder", sortorder);
		}
		rows = corpPublicationMng.findByPage(start, limit, param);
		this.total = corpPublicationMng.getCount(param);
		success = true;
		return SUCCESS;
	}


	

	public String delete() {
		HttpServletRequest request = ServletActionContext.getRequest();
		String ids = request.getParameter("delIds");
		ids = ids.substring(0, ids.length()-1);
		StringTokenizer st = new StringTokenizer(ids, ",", false);
		List<String> StringList = new ArrayList<String>();
		while (st.hasMoreElements()) {
			StringList.add(st.nextToken());
		}
		for (int i = 0; i < StringList.size(); i++) {
			corpPublicationMng.remove(new Long(StringList.get(i)));
		}
		success = true;
		return SUCCESS;
	}

	public String add() {
		success = true;
		return SUCCESS;
	}

	public String modify() {
		//corpPublicationMng.update(corpPublication);
		success = true;
		return SUCCESS;
	}
	
	public String audit() {
		HttpServletRequest request = ServletActionContext.getRequest();
		boolean pass = Boolean.valueOf(request.getParameter("ispass"));
		
		String ids = request.getParameter("auditIds");
		ids = ids.substring(0, ids.length()-1);
		StringTokenizer st = new StringTokenizer(ids, ",", false);
		List<String> StringList = new ArrayList<String>();
		while (st.hasMoreElements()) {
			StringList.add(st.nextToken());
		}
		
		
		for (int i = 0; i < StringList.size(); i++) {
			corpPublicationMng.audit(new Long(StringList.get(i)),pass);
		}
		success = true;
		return SUCCESS;
	}
	
	
	public List<CorpPublication> getRows() {
		return rows;
	}

	public void setRows(List<CorpPublication> rows) {
		this.rows = rows;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}


	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

}
